package com.gem.back.controller;


import com.gem.back.entity.AoaSysMenu;
import com.gem.back.service.IAoaSysMenuService;
import com.gem.vo.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author hhhy
 * @since 2020-02-22
 */
@Controller
@RequestMapping("/a/menu")
public class AoaSysMenuController {
    @Autowired
    private IAoaSysMenuService aoaSysMenuService;
    //菜单管理
    @RequestMapping("/list")
    public String menuManage(){
        return "menu/menuList";
    }

    @ResponseBody
    @RequestMapping("/queryMenuTree")
    public List<Map<String, Object>> queryMenuTree() {
        List<Map<String, Object>> map = aoaSysMenuService.queryMenuTree();
        return map;
    }

    @ResponseBody
    @RequestMapping("/getMenuById")
    public AoaSysMenu getMenuById(Integer menuId) {
        AoaSysMenu sysMenu = aoaSysMenuService.queryMenuById(menuId);
        return sysMenu;
    }

    @RequestMapping("/getParentMenu")
    @ResponseBody
    public AoaSysMenu getParentMenu(Integer menuId) {
        AoaSysMenu sysMenu = aoaSysMenuService.queryParentMenuById(menuId);
        return sysMenu;
    }

    @RequestMapping("/form")
    public String form() {
        return "menuForm";
    }

    @RequestMapping("/save")
    @ResponseBody
    public String save(AoaSysMenu sysMenu) {
        aoaSysMenuService.saveMenu(sysMenu);
        return "success";
    }

    @RequestMapping("/delete")
    @ResponseBody
    public ResponseResult delete(Integer menuId) {
        return aoaSysMenuService.deleteMenu(menuId);
    }
}
